Home / Build / Build your Wallet / Android / Wallet Application Level
Self-signed Certificates
This section describes how to configure the application to interact with services utilizing self-signed certificates.
- Open the build.gradle.kts file of the "core-logic" module.
- In the 'dependencies' block add the following two:
implementation(libs.ktor.android) implementation(libs.ktor.logging) - Now, you need to create a new Kotlin file ProvideKtorHttpClient.kt and place it into the
src\main\java\eu\europa\ec\corelogic\configpackage. - Copy and paste the following code into your newly created ProvideKtorHttpClient.kt file.
import android.annotation.SuppressLint import io.ktor.client.HttpClient import io.ktor.client.engine.android.Android import io.ktor.client.plugins.logging.Logging import java.security.SecureRandom import javax.net.ssl.HostnameVerifier import javax.net.ssl.SSLContext import javax.net.ssl.TrustManager import javax.net.ssl.X509TrustManager import javax.security.cert.CertificateException object ProvideKtorHttpClient { @SuppressLint("TrustAllX509TrustManager", "CustomX509TrustManager") fun client(): HttpClient { val trustAllCerts = arrayOf<TrustManager>( object : X509TrustManager { @Throws(CertificateException::class) override fun checkClientTrusted( chain: Array<java.security.cert.X509Certificate>, authType: String ) { } @Throws(CertificateException::class) override fun checkServerTrusted( chain: Array<java.security.cert.X509Certificate>, authType: String ) { } override fun getAcceptedIssuers(): Array<java.security.cert.X509Certificate> { return arrayOf() } } ) return HttpClient(Android) { install(Logging) engine { requestConfig sslManager = { httpsURLConnection -> httpsURLConnection.sslSocketFactory = SSLContext.getInstance("TLS").apply { init(null, trustAllCerts, SecureRandom()) }.socketFactory httpsURLConnection.hostnameVerifier = HostnameVerifier { _, _ -> true } } } } } } - Finally, add this custom HttpClient to the EUDI Wallet provider function provideEudiWallet located in LogicCoreModule.kt
@Single fun provideEudiWallet( context: Context, walletCoreConfig: WalletCoreConfig, walletCoreLogController: WalletCoreLogController ): EudiWallet = EudiWallet(context, walletCoreConfig.config) { withLogger(walletCoreLogController) // Custom HttpClient withKtorHttpClientFactory { ProvideKtorHttpClient.client() } }